﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FimetContoDeposito.DAL;
using GestionePolveri.DAL;
using GrayParrot.Core;

namespace FimetContoDeposito.BLL.Facades
{
    public class AnagraficaColoriFacade : FacadeBase<AnagraficaColoriFacade>
    {
        GestionePolveriContext m_ctx = null;

        public Repository<GP_AnagColori, Guid> Repo { get; internal set; }

        public AnagraficaColoriFacade()
        {

        }

        public override void Initialize()
        {
            m_ctx = new GestionePolveriContext();
            m_ctx.Configuration.LazyLoadingEnabled = false;
            m_ctx.Configuration.ProxyCreationEnabled = false;

            Repo = this.GetRepository<GP_AnagColori, Guid>(m_ctx);
        }

        public override void Dispose()
        {
            if (m_ctx != null)
            {
                m_ctx.Dispose();

                Repo.Dispose();
            }
        }

        public ReturnValue<IQueryable<GP_AnagColori>> GetAll()
        {
            ReturnValue<IQueryable<GP_AnagColori>> retValue = new ReturnValue<IQueryable<GP_AnagColori>>();
            retValue.HasValue = false;
            retValue.Value = null;

            try
            {
                retValue.Value = this.Repo.GetAll();
                retValue.HasValue = true;
            }
            catch (Exception ex)
            {
                retValue.HasError = true;
                retValue.Error = ex;
            }

            return retValue;
        }
    }
}
